package cn.com.ghy.android.bean;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;

/**
 * @软件著作权:金红叶纸业集团有限公司
 * @系统名称:SFA系统
 * @Description:下月拜访计划中工作方式解析类
 * @author wuz  @date 2011-5-24 15:48:34
 * @版本历史:v1.0
 * @Copyright:Copyright (c) 2011-2012 
 */

public class VisitPlanWorkTypeBeanParser {
	public static List<VisitPlanWorkTypeBean> parseXML(InputStream in) throws Exception {
		XmlPullParser parser = Xml.newPullParser();
		parser.setInput(in, "UTF-8");
		int type = parser.getEventType();

		VisitPlanWorkTypeBean bean = null;
		List<VisitPlanWorkTypeBean> list = null;

		while (type != XmlPullParser.END_DOCUMENT) {
			switch (type) {
				case XmlPullParser.START_DOCUMENT :
					list = new ArrayList<VisitPlanWorkTypeBean>();
					break;

				case XmlPullParser.START_TAG :
					if ("Table".equals(parser.getName())) {
						bean = new VisitPlanWorkTypeBean();
					} else if (null != list && null != bean) {
						if ("WORKTYPE".equals(parser.getName())) {
							bean.setWorkTypeId(Integer.parseInt(parser.nextText()));
						} else if ("WORKTYPENAME".equals(parser.getName())) {
							bean.setWorkTypeName(parser.nextText());
						}
					}
					break;

				case XmlPullParser.END_TAG :
					if ("Table".equals(parser.getName())) {
						if (null != list && null != bean) {
							list.add(bean);
							bean = null;
						}
					}
					break;
			}
			type = parser.next();
		}
		in.close();
		return list;
	}
}
